<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
            navigator.geolocation.getCurrentPosition(function(res){
                console.log('成功获取了',res,res.coords.latitude,res.coords.longitude);
            },function(error){
                switch(error.code){
                    case error.PERMISSION_DENIED:
                    alert('定位失败，用户拒绝请求地址位置');
                    break;
                    case error.POSITION_UNAVAILABLE:
                    alert('定位失败，位置信息是不可用');
                    break;
                    case error.TIMEOUT:
                    alert('定位失败，请求获取用户的位置超时');
                    break;
                    case error.UNKNOWN_ERROR:
                    alert('定位失败，定位系统失败');
                    break;
                }
            },{
           
                enableHighAccuracy:true,
            
                timeout:10000,
               
                maximumAge:3000
            })
     </script>

</body>
</html>